package zzl.reactorfun;

import org.junit.Ignore;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import java.util.Locale;

public class FluxLoggingTests {

    @Test
    @Ignore
    public void logSimple(){
        Flux<String> beltColors = Flux.just(
                "white", "yellow", "orange", "green", "purple", "blue"
        ).log();
        beltColors.subscribe();
    }

    @Test
    @Ignore
    public void logMapping(){
        Flux<String> beltColors = Flux.just(
                "white", "yellow", "orange", "green", "purple", "blue"
        ).map(cb -> cb.toUpperCase(Locale.ROOT)).log();
        beltColors.subscribe();
    }

    @Test
    public void logFlatMapping() throws InterruptedException {
        Flux<String> beltColors = Flux.just(
                "white", "yellow", "orange", "green", "purple", "blue"
        ).flatMap(cb -> Mono.just(cb)
        .map(c -> c.toUpperCase(Locale.ROOT))
        .log()
        .subscribeOn(Schedulers.parallel()));
        beltColors.subscribe();

        Thread.sleep(3000L);
    }
}
